package com.sx.medicinecard.common;

import lombok.Data;

/**
 * 请求返回体
 */
@Data
public class ResponseResult {

    /**
     * 状态码
     */
    private Integer code;

    /**
     * 返回信息
     */
    private String message;

    /**
     * 数据
     */
    private Object data;

    public ResponseResult fail(Integer code, String message){
        this.setCode(code);
        this.setMessage(message);
        return this;
    }

    public static ResponseResult error(String message){
        ResponseResult responseResult = new ResponseResult();
        responseResult.setCode(HttpStatusEnum.ERROR.getCode());
        responseResult.setMessage(message);
        return responseResult;
    }


    public static ResponseResult error(Integer code, String message){
        ResponseResult responseResult = new ResponseResult();
        responseResult.setCode(code);
        responseResult.setMessage(message);
        return responseResult;
    }

    public static ResponseResult error(String message,Object data){
        ResponseResult responseResult = new ResponseResult();
        responseResult.setCode(HttpStatusEnum.SUCCESS.getCode());
        responseResult.setMessage(message);
        responseResult.setData(data);
        return responseResult;
    }

    public static ResponseResult success(String message,Object data){
        ResponseResult responseResult = new ResponseResult();
        responseResult.setCode(HttpStatusEnum.SUCCESS.getCode());
        responseResult.setMessage(message);
        responseResult.setData(data);
        return responseResult;
    }

    public static ResponseResult success(Object data){
        ResponseResult responseResult = new ResponseResult();
        responseResult.setCode(HttpStatusEnum.SUCCESS.getCode());
        responseResult.setMessage(HttpStatusEnum.SUCCESS.getMessage());
        responseResult.setData(data);
        return responseResult;
    }

    public ResponseResult ok(Object data){
        ResponseResult responseResult = new ResponseResult();
        responseResult.setCode(HttpStatusEnum.SUCCESS.getCode());
        responseResult.setMessage(HttpStatusEnum.SUCCESS.getMessage());
        responseResult.setData(data);
        return responseResult;
    }

}
